import { Component, OnInit } from '@angular/core';
import { RepairService } from "../../repair.service";
import { flyIn } from '../../../../animations/fly-in';
import { PageModel } from "../../../../model/page-model";
import { ActivatedRoute,Router } from '@angular/router';
@Component({
  selector: 'app-order-detail',
  templateUrl: './order-detail.component.html',
  styleUrls: [
    './order-detail.component.css',
    '../../../../../assets/css/timeline.css'],
  animations: [
    flyIn
  ]
})
export class OrderDetailComponent implements OnInit {

  orderId:string = '';
  data;
  items = [];
  pageModel = new PageModel();
  page:number = 1;
  constructor(private _router: Router,private activeRoute:ActivatedRoute,private repairService:RepairService) { }

  ngOnInit() {
    this.activeRoute.params.subscribe(
      params=> {

        this.orderId = this.repairService.orderId = params['orderId'];

        this.repairService.getData().subscribe(res => {
          this.data = res.result;
        }, err => console.log(err));

        this.repairService.getAllItems().subscribe(
          res=> {
            for (let i = 0; i < res.result.length; i += 5) {
              this.items.push(res.result.slice(i, i + 5));
            }
            this.pageModel.setPage({'iTotalRecords': res.result.length});
          }
        );

      }
    );
  }

  cancel(){
    this._router.navigateByUrl('page/repair/order');
  }
}
